package com.system.integralserver.service.impl;

import com.system.commonutils.pojo.UsePoints;
import com.system.integralserver.mapper.IntegralMapper;
import com.system.integralserver.pojo.IntegralInfo;
import com.system.integralserver.pojo.Orders;
import com.system.integralserver.service.IntegralService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ll
 * Date: 2020/07/09 15:06
 * Description:
 * Version: V1.0
 */
@Service
public class IntegralServiceImpl implements IntegralService {
    @Autowired
    IntegralMapper integralMapper;

    @Override
    public Orders getMessage(Integer order_id) {
        Orders orders = integralMapper.getMessage(order_id);
        System.out.println("=========" + orders);
        return orders;
    }

    @Override
    public int createIntegral(IntegralInfo integralInfo) {
        int rs = integralMapper.createIntegral(integralInfo);
        return rs;
    }

    @Override
    public Integer useIntegral(UsePoints usePoints) {
        usePoints.setIntegralInfo_integral((int)(0-usePoints.getCoupon_money()/1));
        usePoints.setIntegralInfo_createTime(new Date());
        return integralMapper.useIntegral(usePoints);
    }

    @Override
    public List<UsePoints> queryIntegralInfo(UsePoints usePoints) {
        Integer nowsPage = usePoints.getNowsPage();
        usePoints.setNowsPage((nowsPage-1)*usePoints.getPageSize());
        return integralMapper.queryIntegralInfo(usePoints);
    }

    @Override
    public Integer countInfo(UsePoints usePoints) {
        return integralMapper.countInfo(usePoints);
    }
}
